<?php
//Zend_Loader::loadFile('../application/admin/models/Template.php');
class Newsletter 
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function listNewsletters()
    {
    	$getNewsletters = $this->_db->fetchAll("
			SELECT newsletter_id, newsletter_title, newsletter_content, template_id
			FROM newsletters 
			
		");
		
		return $getNewsletters;
	}
	

    public function getNewsletter($newsletter_id)
    {
    //	echo $newsletter_id;exit;
    	$getNewsletterdetails = $this->_db->fetchrow("
			select newsletter_id, newsletter_title, newsletter_content, template_id
			from  newsletters where  newsletter_id='".$newsletter_id."'
			
		");
		//print_r($getNewsletterdetails);
		return $getNewsletterdetails;
       
    }

    public function addNewsletter($template_id,$newsletter_title,  $newsletter_content,$newsletter_id=0)
    {
         
      $addNewsletters = $this->_db->exec("
      insert into newsletters (newsletter_title,newsletter_content,template_id,status) 
      values ('".$newsletter_title."','".$newsletter_content."','".$template_id."',1)
	  ");
    	/*$command="call proc_newsletter('ADD','".$newsletter_title."','".$newsletter_content."',".$template_id.",".$newsletter_id.",1)";
        echo  $command;exit;
		$addNewsletters = $this->_db->exec($command);*/
		return $addNewsletters;
    }

    public function updateNewsletter($newsletter_id, $newsletter_title, $newsletter_content,$template_id)
    {
      $EditNewsletters = $this->_db->exec("
      update  newsletters set newsletter_title='".$newsletter_title."' ,newsletter_content='".$newsletter_content."',template_id='".$template_id."' 
       WHERE  newsletter_id=".$newsletter_id."
		");
    	/*$command="call proc_newsletter('EDIT','".$newsletter_title."','".$newsletter_content."',".$template_id.",".$newsletter_id.",1)";
    	//echo  $command;exit;
		$EditNewsletters = $this->_db->exec($command);*/
		return $EditNewsletters;
        
    }

    public function deleteNEwsletter($newsletter_id)
    {
    	$command="delete from newsletters where newsletter_id=".$newsletter_id."";
    	
    	// echo $command;exit;
       $DeleteNewsletters = $this->_db->exec($command);
      
		return $DeleteNewsletters;
        
    }

}

